# 进程  带参数
"""

"""
import os
from multiprocessing import Process
from time import sleep


def task1(second):
    while True:
        sleep(second)
        print("这是任务1----------", os.getpid(), ": ", os.getppid())  # getppid:获取父ID


def task2(second):
    while True:
        sleep(second)
        print("这是任务2----------", os.getpid(), ": ", os.getppid())


# 创建进程
number = 1
if __name__ == '__main__':
    print("当前进程的号：", os.getpid())
    p1 = Process(target=task1, name="task1", args=(1,))  # args=(1,)  元组当只有一个元素的时候加了，才是否则就是字符串
    p1.start()
    print(p1.name)
    p2 = Process(target=task2, name="task2", args=(2,))
    p2.start()
    print(p2.name)
    while True:
        number += 1
        sleep(0.2)
        if number == 100:
            p1.terminate()
            p2.terminate()
            break
        else:
            print(number)
